package thread.newCachedThreadPool;


import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Pool {
    public static void main(String[] args) {
        ExecutorService pool = Executors.newCachedThreadPool();
        pool.submit(new Runnable() {
            @Override
            public void run() {
                //执行业务逻辑
                for(int i = 1; i <= 100; i++) {
                    System.out.println("线程:" + Thread.currentThread().getName() + "执行了任务" + i + "~");
                }
            }
        });
        pool.submit(new Runnable() {
            @Override
            public void run() {
                //执行业务逻辑
                for(int i = 101; i <= 200; i++) {
                    System.out.println("线程:" + Thread.currentThread().getName() + "执行了任务" + i + "~");
                }
            }
        });
        pool.submit(new Runnable() {
            @Override
            public void run() {
                //执行业务逻辑
                for(int i = 201; i <= 300; i++) {
                    System.out.println("线程:" + Thread.currentThread().getName() + "执行了任务" + i + "~");
                }
            }
        });
    }
}
